package cn.techwis.service;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.techwis.dto.QueryOrderDTO;
import cn.techwis.common.WxApi;
import cn.techwis.vo.InItVO;
import cn.techwis.vo.PayQueryVO;
import cn.techwis.util.WxHttpUtil;


/**
 * 订单查询
 */
public class PayQueryService extends Tservice {


    /**
     * 微信支付订单号查询
     */
    public static QueryOrderDTO jsapiOrderQuery(PayQueryVO payQueryVO, InItVO inItVO) {
        validateObject(payQueryVO, PayQueryVO.PayQuery.class, inItVO);
        JSONObject jsonObject = new JSONObject();
        if (StrUtil.isNotEmpty(payQueryVO.getTransaction_id())) {
            jsonObject = WxHttpUtil.requestGet("支付订单查询", StrUtil.format(WxApi.payQuery.TRANSACTIONS, payQueryVO.getTransaction_id(), payQueryVO.getMchid()), inItVO.getPrivateKeyFileName(), payQueryVO.getMchid(), inItVO.getSerialNo());
        } else if (StrUtil.isNotEmpty(payQueryVO.getOut_trade_no())) {
            jsonObject = WxHttpUtil.requestGet("支付订单查询", StrUtil.format(WxApi.payQuery.OUTTRADENO, payQueryVO.getOut_trade_no(), payQueryVO.getMchid()), inItVO.getPrivateKeyFileName(), payQueryVO.getMchid(), inItVO.getSerialNo());
        }
        return queryResult(jsonObject);
    }


    public static void main(String[] args) {
        PayQueryVO payQueryVO = new PayQueryVO();
        payQueryVO.setMchid("1505026761");
        payQueryVO.setTransaction_id("4200000813202012045110404568");
        InItVO inItVO = new InItVO();
        inItVO.setPrivateKeyFileName("C:\\Users\\yando\\Desktop\\apiclient_key.pem");
        inItVO.setSerialNo("71B1200AE00607AA44A2EC99DB14387CF266C354");
        inItVO.setMchId("1505026761");
        QueryOrderDTO queryOrderDTO = jsapiOrderQuery(payQueryVO, inItVO);

    }
}
